﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:RawExplorer2.UI">
    <DataTemplate x:Key="ColorNumberArgDataTemplate">
        <Grid x:Name="ColorNumberPicker">
            <Grid Width="Auto" HorizontalAlignment="Stretch">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <TextBox Width="50"
                         HorizontalAlignment="Right"
                         Text="{Binding Path=Value,
                                        Mode=TwoWay,
                                        UpdateSourceTrigger=PropertyChanged}" />
                <Rectangle Grid.Column="1"
                           Margin="2"
                           Fill="{Binding Path=Value,
                                          Converter={local:ColorNumberConverter}}"
                           RadiusX="3"
                           RadiusY="3"
                           Stroke="Black" />
                <ToggleButton x:Name="DropdownToggle"
                              Grid.Column="2"
                              Width="32"
                              IsChecked="{Binding Path=IsColorMenuOpen,
                                                  Mode=TwoWay,
                                                  UpdateSourceTrigger=PropertyChanged}"
                              IsHitTestVisible="{Binding ElementName=ColorNumberPopup,
                                                         Path=IsOpen,
                                                         Converter={local:BooleanInverterConverter},
                                                         Mode=OneWay}">
                    <Path Width="6"
                          Margin="4"
                          HorizontalAlignment="Center"
                          VerticalAlignment="Center"
                          Data="{StaticResource DropDownPath}"
                          Fill="#FF527DB5"
                          Stretch="Uniform" />
                </ToggleButton>
            </Grid>
            <Popup x:Name="ColorNumberPopup"
                   Width="{Binding ElementName=ColorNumberPicker,
                                   Path=ActualWidth}"
                   AllowsTransparency="True"
                   IsOpen="{Binding Path=IsColorMenuOpen,
                                    Mode=TwoWay,
                                    UpdateSourceTrigger=PropertyChanged}"
                   Placement="Bottom"
                   PlacementTarget="{Binding ElementName=ColorNumberPicker}"
                   PopupAnimation="Slide"
                   StaysOpen="False">
                <Border Margin="0,0,8,8">
                    <Border.Effect>
                        <DropShadowEffect />
                    </Border.Effect>
                    <DataGrid HorizontalAlignment="Stretch"
                              VerticalAlignment="Stretch"
                              AutoGenerateColumns="False"
                              CanUserAddRows="false"
                              CanUserReorderColumns="False"
                              CanUserResizeColumns="False"
                              CanUserResizeRows="False"
                              CanUserSortColumns="False"
                              ItemsSource="{Binding Path=ColorSet}"
                              RowHeaderWidth="0"
                              SelectedValue="{Binding Path=Value,
                                                      Converter={local:StringToIntegerConverter},
                                                      Mode=TwoWay,
                                                      UpdateSourceTrigger=PropertyChanged}"
                              SelectedValuePath="Index"
                              SelectionMode="Single">
                        <DataGrid.Resources>
                            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Color="{x:Static SystemColors.HighlightColor}" />
                            <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightTextBrushKey}" Color="{x:Static SystemColors.HighlightTextColor}" />
                        </DataGrid.Resources>
                        <DataGrid.RowStyle>
                            <Style TargetType="DataGridRow">
                                <Style.Triggers>
                                    <Trigger Property="IsMouseOver" Value="True">
                                        <Setter Property="Background" Value="{x:Static SystemColors.HotTrackBrush}" />
                                        <Setter Property="Foreground" Value="{x:Static SystemColors.HighlightTextBrush}" />
                                        <Setter Property="BorderBrush" Value="{x:Static SystemColors.HighlightBrush}" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </DataGrid.RowStyle>
                        <DataGrid.Columns>
                            <DataGridTextColumn Binding="{Binding Path=Index}"
                                                Header="Number"
                                                IsReadOnly="True" />
                            <DataGridTextColumn Binding="{Binding Path=Name}"
                                                Header="Name"
                                                IsReadOnly="True" />
                            <DataGridTemplateColumn Width="*"
                                                    Header="Color"
                                                    IsReadOnly="True">
                                <DataGridTemplateColumn.CellTemplate>
                                    <DataTemplate>
                                        <Rectangle Margin="1"
                                                   HorizontalAlignment="Stretch"
                                                   Fill="{Binding Path=Color,
                                                                  Converter={local:GdiColorConverter}}"
                                                   RadiusX="3"
                                                   RadiusY="3"
                                                   Stroke="Black" />
                                    </DataTemplate>
                                </DataGridTemplateColumn.CellTemplate>
                            </DataGridTemplateColumn>
                        </DataGrid.Columns>
                    </DataGrid>
                </Border>
            </Popup>
        </Grid>
    </DataTemplate>
</ResourceDictionary>